package com;

import com.netflix.config.ConfigurationManager;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixThreadPoolKey;

public class ThreadIsolatedDemo extends HystrixCommand<String> {

	private String name;	
	public ThreadIsolatedDemo(String name) {
		super(Setter.withGroupKey(HystrixCommandGroupKey.Factory
				.asKey("ThreadIsolatedDemo")).andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey("ThreadGroup") )  );
		this.name = name;
	}

	protected String run() throws Exception {
		System.out.println("In Run Name is：" + name);
		return name;
	}

	protected String getFallback() {
		System.out.println("In GetFallBack, name is:" + name);
		return name;
	}
	
	public static void main(String[] args) {
		//不开启断路器
		ConfigurationManager.getConfigInstance().setProperty("hystrix.command.default.circuitBreaker.forceOpen", "false");
		// 配置线程池大小为2
		ConfigurationManager.getConfigInstance().setProperty(
						"hystrix.threadpool.default.coreSize", 2);
				
		for(int ind = 1; ind <= 3; ind++) {
		    ThreadIsolatedDemo demo = new ThreadIsolatedDemo(Integer.valueOf(ind).toString());
		    demo.queue();
		}

	}

}
